package workflow

import "encoding/json"

type WorkFlowContext struct {
	Context map[string]any
}

// value must support to marshal
func (c *WorkFlowContext) Put(key string, value any) {
	c.Context[key] = value
}

func (c *WorkFlowContext) Get(key string) any {
	return c.Context[key]
}

func (c *WorkFlowContext) Remove(key string) {
	delete(c.Context, key)
}

func FromBytes(data []byte) (*WorkFlowContext, error) {
	ctx := &WorkFlowContext{}

	if err := json.Unmarshal(data, ctx); err != nil {
		return nil, err
	}

	return ctx, nil
}

func (c *WorkFlowContext) ToBytes() ([]byte, error) {
	data, err := json.Marshal(c)

	return data, err
}
